package io.github.pigmesh.ai.deepseek.example.deepseek;

import cn.dev33.satoken.stp.StpUtil;
import io.github.pigmesh.ai.deepseek.core.ChatWithPromptTemplate;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import io.github.pigmesh.ai.deepseek.core.chat.ChatWithHistoryDTO;
import io.github.pigmesh.ai.deepseek.core.chat.ChatWithTemplate;
import io.github.pigmesh.ai.deepseek.core.models.ModelsResponse;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriUtils;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;
import java.net.URLDecoder;
import java.net.URLEncoder;

@RestController
@RequestMapping
public class DeepSeekLocalController {

	@Resource
	private DeepSeekClient deepSeekClient;

	@GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
	public Flux<ChatCompletionResponse> chat(String prompt) {
		return deepSeekClient.chatFluxCompletion(prompt);
	}

	@PostMapping(value = "/chatWithHistory", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
	public Flux<ChatCompletionResponse> chatWithHistory(@RequestBody ChatWithHistoryDTO dto) {
		return deepSeekClient.chatWithHistory(dto);
	}

	@PostMapping(value = "/chatWithTemplate", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
	public Flux<ChatCompletionResponse> chatWithTemplate(@RequestBody ChatWithTemplate dto) {
		return deepSeekClient.chatWithTemplate(dto);
	}

	@PostMapping(value = "/chatWithPromptTemplate", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
	public Flux<ChatCompletionResponse> chatWithPromptTemplate(@RequestBody ChatWithPromptTemplate dto) {
		return deepSeekClient.chatWithPromptTemplate(dto);
	}

//	@PostMapping(value = "/chatWithTemplateId", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
//	public Flux<ChatCompletionResponse> chatWithTemplate(@RequestBody ChatWithTemplateId dto) {
//		return deepSeekClient.chatWithTemplate(dto);
//	}


	@GetMapping(value = "/chatSearchCompletion", produces = MediaType.TEXT_EVENT_STREAM_VALUE + "; charset=UTF-8")
	public Flux<ChatCompletionResponse> chatSearchCompletion(String prompt) {
		return deepSeekClient.chatSearchCompletion(prompt);
	}

	@GetMapping(value = "/models", produces = MediaType.APPLICATION_JSON_VALUE)
	public ModelsResponse models() {
		return deepSeekClient.models();
	}

	public static void main(String[] args) {
		String encode = UriUtils.encode("新能源汽车优势在哪里", "UTF-8");
		System.out.println(encode);
	}
}
